import 'package:flutter/material.dart';
import './pages/home_page.dart';
import './pages/fenxiang_page.dart';
import './pages/search_paeg.dart';
import './pages/my_page.dart';
class ButtomTabbar extends StatefulWidget {
  ButtomTabbar({Key key}) : super(key: key);

  @override
  _ButtomTabbarState createState() => _ButtomTabbarState();
}

class _ButtomTabbarState extends State<ButtomTabbar> {
  static Color _defaultColor = Colors.grey;
  static Color _activeColor = Colors.blueAccent;
  // ignore: non_constant_identifier_names
  int _curr_index = 0;
  List<Map> BottomTabList= [
    {'index':0,'title':'首页','icon':Icon(Icons.home,color: _defaultColor,),'activeIcon':Icon(Icons.home,color: _activeColor,)},
    {'index':1,'title':'搜索','icon':Icon(Icons.search,color: _defaultColor,),'activeIcon':Icon(Icons.search,color: _activeColor,)},
    {'index':2,'title':'分享','icon':Icon(Icons.photo_camera,color: _defaultColor,),'activeIcon':Icon(Icons.photo_camera,color: _activeColor,)},
    {'index':3,'title':'我的','icon':Icon(Icons.pregnant_woman,color: _defaultColor,),'activeIcon':Icon(Icons.pregnant_woman,color: _activeColor,)},
  ];



  final PageController _controller = PageController(
    initialPage: 0
  );
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: PageView(
        controller: _controller,
        children: <Widget>[
          HomePage(),
          SearchPage(hideLeft: true,),
          FenxiangPage(),
          My_page()
        ],
        physics:NeverScrollableScrollPhysics(),
      ),
      bottomNavigationBar:BottomNavigationBar(
        currentIndex: _curr_index,
        onTap: (index){
          _controller.jumpToPage(index);
//          print(index);
          setState(() {
            _curr_index = index;
          });
        },
        items:
          BottomTabList.map((item){
//            print(item);
            return BottomNavigationBarItem(
                icon:item['icon'],
                activeIcon: item['activeIcon'],
                title: Text(item['title'],style: TextStyle(color: _curr_index == item['index'] ?Colors.blueAccent:Colors.grey),)
            );
          }).toList(),


        type: BottomNavigationBarType.fixed,
      ) ,
    );
  }
}